package ro.flashbite.loggers.targets
{
	import ro.flashbite.loggers.LoggerLevels;
	import ro.flashbite.loggers.targets.ILoggingTarget;

	/**
	 * This class creates a smart trace representation of an object
	 * 
	 * v 1.0
	 * 
	 * @author Adrian Barbu
	 */	
	public class TraceLoggingTarget implements ILoggingTarget
	{
		/**
		 * direct acces to transformation function for code performance 
		 */		
		private var _levelToStringFunc	:	Function = LoggerLevels.levelToString;
		
		// ================================================================================================================================
		// CONSTRUCTOR
		// ================================================================================================================================
		
		public function TraceLoggingTarget() {}
		
		// ================================================================================================================================
		// ILogTarget implementation
		// ================================================================================================================================
		
		/**
		 * Create a smart trace output based on logger and level
		 *  
		 * @param loggerName : (String) the logger name used
		 * @param level : (uint) the logger level used to debug
		 * @param message : (Object) the message to trace
		 */		
		public function logMessage(loggerName:String, level:int, ...message):void
		{
			trace(createMessage(loggerName, level, message));
		}
		
		// ================================================================================================================================
		// PROTECTED
		// ================================================================================================================================
		
		/**
		 * Create a representation of a normal trace statement to a specific output;
		 * ex: createMessage("Smart", 1, "Hello") will output "[Smart] [DEBUG] Hello!"
		 *  
		 * @param loggerName : (String) the logger name used
		 * @param level : (uint) the logger level used to debug
		 * @param message : (Object) the message to trace
		 * @return : (String) smart representation of trace output from specific class 
		 */		
		protected final function createMessage(loggerName:String, level:int, ...message):String
		{
			return ("[" + loggerName + "] " + "[" + _levelToStringFunc(level) + "] " + message);
		}
		
		// ================================================================================================================================
		// DESTRUCTOR
		// ================================================================================================================================
		
		/**
		 * Proper destroy 
		 */		
		public function destroy():void
		{
			_levelToStringFunc = null;
		}
	}
}